package org.example.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.dto.CategoryDTO;
import org.example.dto.OPtionsDTO;
import org.example.dto.SpecDTO;
import org.example.entity.Category;
import org.example.vo.SpecVO;

import java.util.List;

@Mapper
public interface Shanpinguigemapper {

    /**
     * 商品规格查询
     * @param username
     * @return
     */
    @Select("select id,name from categories where username=#{username}")
    List<Category> cx(String username);

    /**
     * 查询规格值
     * @param id
     */
    @Select("select id,spec_name  from specs where category_id=#{id}")
    List<SpecVO> cxguigezhi(String id);

    /**
     * 查询
     * @param id
     * @return
     */
    @Select("select option_value from options where spec_id=#{id}")
    List<String> cxoption(int id);

    /**
     * 新增分类
     * @param
     */
    @Insert("INSERT INTO categories (name,id,username)\n" +
            "VALUES\n" +
            "(#{name},#{id},#{username})")
    void xzfele(CategoryDTO categoryDTO);

    /**
     * 删除分类
     * @param username
     * @param id
     */
    @Delete("delete from categories where username=#{username} and id=#{id}")
    void scfele(String username, String id);

    /**
     * 新增规格
     * @param specDTO
     */
    @Insert("INSERT INTO specs (category_id,spec_name,username)\n" +
            "VALUES\n" +
            "(#{id},#{name},#{username})")
    void xzgui(SpecDTO specDTO);

    /**
     * 删除规格
     * @param username
     * @param id
     */
    void scgui(String username, String id,String name);

    /**
     * 查询规格id
     * @param username
     * @param id
     * @param name
     * @return
     */
    List<Integer> sccx(String username, String id, String name);

    /**
     * 规格值新增
     * @param oPtionsDTO
     */
    @Insert("INSERT INTO options (spec_id,option_value)\n" +
            "VALUES\n" +
            "(#{id},#{name})")
    void xzguizhi(OPtionsDTO oPtionsDTO);

    /**
     * 查询规格
     * @param spec
     * @return
     */
    @Select("select id from specs where spec_name=#{spec} and category_id=#{categoryid} and username=#{username}")
    int cxguige(OPtionsDTO spec);

    /**
     * 删除规格值
     *
     * @param name
     * @param specid
     */
    @Delete("delete from options where  option_value=#{name} and spec_id=#{specid}")
    void scguizhi(String name, int specid);

    /**
     * 删除规格和规格值
     * @param specid
     */
    @Delete("delete from options where  spec_id=#{specid}")
    void scguizhis(int specid);

    /**
     * 查询规格值
     * @param id
     * @param specname
     * @return
     */
    @Select("select id from specs where spec_name=#{specname} and category_id=#{id} " +
            "and username=#{username}")
    int chaxuguigezhi(String id, String specname,String username);
}
